﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DNA.Mvc.Notification
{
    /// <summary>
    /// Presents Subscription sender send private message to users.
    /// </summary>
    public class PrivateMessageSubscriptionSender : SubscriptionSenderBase
    {
        public IPrivateMessageRepository msgRpository;

        public PrivateMessageSubscriptionSender(IPrivateMessageRepository repository)
        {
            msgRpository = repository;
        }

        public override void Send(string[] subscribers, IMessage message)
        {
            if ((subscribers != null) && (message != null))
            {
                var privateMsg = message as PrivateMessage;
                if (privateMsg == null)
                    privateMsg = new PrivateMessage(message);
                privateMsg.Receivers = string.Join(",", subscribers);
                privateMsg.Received = DateTime.UtcNow;
                msgRpository.Create(privateMsg);
                msgRpository.Submit();
            }
        }
    }
}
